package cn.jsoup;

import cn.wanghaomiao.xpath.exception.XpathSyntaxErrorException;
import cn.wanghaomiao.xpath.model.JXDocument;
import cn.wanghaomiao.xpath.model.JXNode;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class jsoupDemo4 {
    public static void main(String[] args) throws IOException, XpathSyntaxErrorException {
        String path = jsoupDemo4.class.getClassLoader().getResource("student.xml").getPath();
        //获取html路径
        Document document = Jsoup.parse(new File(path), "UTF-8");
        //将html文件进行解析
        JXDocument jd=new JXDocument(document);
        List<JXNode> jxNodes = jd.selN("//student");
        for (JXNode jxNode : jxNodes) {
            System.out.println(jxNode);
        }
        System.out.println("--------");
        List<JXNode> jxNodes1 = jd.selN("//student/name");
        List<JXNode> jxNodes2 = jd.selN("//student/name[@id='heima']");
        for (JXNode jxNode : jxNodes1) {
            Element element = jxNode.getElement();
            String text = element.text();
            System.out.println(text);
        }
    }
}
